package com.zy.explore.license.interfaces.facade.v1;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zy.explore.license.domain.mybatis.entity.CustomerLicenseInfo;
import com.zy.explore.license.infrastructure.constant.CustomerLicenseInfoRouter;
import com.zy.explore.license.interfaces.assembler.CustomerLicenseInfoAssembler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * description 表(customer_license_info)对应mybatis-plus的Facade扩展类
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2022年04月06日 10:13:39
 */
@Api(tags = "CustomerLicenseInfoFacade扩展门面")
@RestController
@RequestMapping(CustomerLicenseInfoRouter.CUSTOMER_LICENSE_INFO)
public class CustomerLicenseInfoFacadeExt {

    /**
     * 注入服务
     */
    @Resource
    private CustomerLicenseInfoAssembler assembler;

    /**
     * 校验客户名称是否重复
     *
     * @param customerName 客户名称
     * @return 返回对象
     */
    @ApiOperationSupport(order = 10, author = "🇨🇳中国印🇨🇳")
    @ApiOperation("1校验客户名称是否重复")
    @GetMapping("/checkCustomerName")
    public boolean checkCustomerName(String id, String customerName) {
        QueryWrapper<CustomerLicenseInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("customer_name", customerName);
        List<CustomerLicenseInfo> list = CustomerLicenseInfo.builder().build().findList(wrapper);
        if (StringUtils.isBlank(id)) {
            return CollectionUtils.isNotEmpty(list);
        }
        return CollectionUtils.isNotEmpty(list) && list.size() > 1;
    }



}
